package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Sign;
import cn.wolfcode.trip.base.service.ISignService;
import cn.wolfcode.trip.base.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/signs")

public class SignController {

    @Autowired
    private ISignService signService;

    /**
     * 查询本月签到总天数
     * @param userId
     * @return
     */
    @RequestMapping(value = "/{userId}",method = RequestMethod.GET)
    public JsonResult saveComment(@PathVariable("userId") Long userId){
        JsonResult result = new JsonResult();
        try {
            List<Sign> list = signService.selectAllDays(userId);
            result.setResult(list);

        } catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }

    /**
     * 新增签到
     * @param sign
     * @return
     */
    @RequestMapping(value = "/saveSign/{userId}",method = RequestMethod.POST)
    public JsonResult saveSign(Sign sign){
        JsonResult result = new JsonResult();
        try {
            signService.save(sign);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }

    @RequestMapping(value = "/selectStates",method = RequestMethod.GET)
    public JsonResult selectState(){
        int i = signService.SelectSignState();
        return new JsonResult().setResult(i);
    }

}